package worldinruin.controllers;

import worldinruin.gui.IGui;
import worldinruin.gui.imp.MainFrame;
import worldinruin.gui.imp.gameview.GameViewMainPanel;
import worldinruin.gui.imp.gameview.gameboard.ITilePiece;
import worldinruin.resources.Panels;

public class PanelController {
	
	private static PanelController instance;
	private GameViewMainPanel gameView;
	private IGui mainFrame;
	
	/**
	 * Creates a single instance of PanelController.
	 */
	private PanelController() {
		gameView = GameViewMainPanel.getInstance();
		mainFrame = MainFrame.getInstance();
	}
	
	/**
	 * Method used to create the single instance of PanelController.
	 * @return Single instance of PanelController.
	 */
	public static PanelController getInstance() {
		
		if (instance == null) {
			instance = new PanelController();
		}
		
		return instance;
	}
	
	/**
	 * Shows a panel in the mainframe.
	 * @param container Container for mainframe.
	 * @param card Which panel to show.
	 */
	public void showPage(String container, String card) {
		if (container.equals(Panels.FRAMEVIEWCARDSTACK.toString())) {
			mainFrame.showPage(card);
		}
	}
	
	/**
	 * Show a panel in the gameviewmainpanel.
	 * @param container A panel in the gameviewmainpanel.
	 * @param panel Which panel to show.
	 */
	public void showPage(Panels container, Panels panel) {
		if (container == Panels.GAMEVIEWLEFTCARDSTACK) {
			gameView.showPage(container, panel);
		}
		
		else if (container == Panels.GAMEVIEWRIGHTCARDSTACK) {
			gameView.showPage(container, panel);
		}
	}
    
	/**
	 * 
	 * @param container
	 * @param panel
	 * @param object
	 */
	public void showPage(Panels container, Panels panel , Object object) {
		if (container == Panels.GAMEVIEWLEFTCARDSTACK) {
			gameView.showPage(container, panel, object);
		}
		
		else if (container == Panels.GAMEVIEWRIGHTCARDSTACK) {
			gameView.showPage(container, panel, object);
		}
	}


	/**
	 * Shows the object of the tilepiece on the gameboard.
	 * @param tilePiece Tile on the gameboard.
	 */
	public void showPage(ITilePiece tilePiece) {
		
		showPage(tilePiece.getCardStack(), tilePiece.getSubPanelType(), tilePiece.getPieceModel());
		
	}
	 
}
